package com.lancoo.znbkxx.teacher.viewmodel

import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
import com.lancoo.znbkxx.teacher.Ext
import com.lancoo.znbkxx.teacher.Ext.Companion.executeResponse
import com.lancoo.znbkxx.teacher.base.BaseViewModel
import com.lancoo.znbkxx.teacher.model.data.HardSolution
import com.lancoo.znbkxx.teacher.model.data.ReviewedDetail
import com.lancoo.znbkxx.teacher.model.repository.CheckScoreRepository
import com.lancoo.znbkxx.teacher.model.repository.CommentsRepository

/**
 * @author : Admin
 * @date   : 2019/7/11 16:09
 * @desc   :
 */
class CommentViewModel(application: Application) : BaseViewModel(application) {
    val mHardSolution = MutableLiveData<HardSolution>()
    val reviewedDetail = MutableLiveData<ReviewedDetail>()
    val unfinishedNum: MutableLiveData<Int> =
            mHardSolution.map { it.UnFinishedList.size } as MutableLiveData<Int>
    val finishedNum: MutableLiveData<Int> =
            mHardSolution.map { it.FinishedList.size } as MutableLiveData<Int>
    val openRzzd = MutableLiveData<Boolean>()
    private val rzzdRepository by lazy { CheckScoreRepository() }

    val mErrorMsg = MutableLiveData<String>()
    private val repository by lazy { CommentsRepository() }


    fun getHardSolutionList(
            Token: String,
            TID: String,
            CourseClassID: String,
            SchoolID: String
    ) {
        launch {
            val result = repository.getHardItemSolutionList(
                    Token,
                    TID,
                    CourseClassID,
                    SchoolID
            )
            executeResponse(
                    result,
                    { mHardSolution.value = result.Data },
                    { mErrorMsg.value = result.Message })
        }
    }

    fun getHardQuesPassedOrFailedStu(
            CourseClassID: String,
            Key: String,
            QueID: String,
            SchoolID: String,
            SubjectID: String,
            Token: String,
            UserID: String
    ) {
        launch {
            val result = repository.getHardQuesPassedOrFailedStu(
                    CourseClassID,
                    Key,
                    QueID,
                    SchoolID,
                    SubjectID,
                    Token,
                    UserID
            )
            executeResponse(result, { reviewedDetail.value = result.Data },
                    { mErrorMsg.value = result.Message })
        }
    }


    fun openClassRzzd() {
        launch {
            val result = rzzdRepository.openClassRzzd()
            Ext.executeResponse(
                    result,
                    { openRzzd.value = result.Data },
                    { mErrorMsg.value = result.Message })
        }
    }

}